package net.dotool.thread;

import java.util.concurrent.TimeUnit;

import net.dotool.i.ICallback;

/**
 * 退出线程
 * 
 * @author 李岩飞
 * @email eliyanfei@126.com
 * @date 2018年11月22日下午2:11:02
 */
public class ExitThread implements Runnable {
	private long t = System.currentTimeMillis();
	private int minute;
	private ICallback callback;

	public ExitThread(int minute) {
		this.minute = minute;
	}

	public ExitThread(int minute, ICallback callback) {
		this.minute = minute;
		this.callback = callback;
	}

	@Override
	public void run() {
		while (true) {
			try {
				TimeUnit.SECONDS.sleep(10);
			} catch (Exception e) {
				e.printStackTrace();
			}
			if (System.currentTimeMillis() - t > minute * 60 * 1000) {
				if (callback != null) {
					callback.done();
				}
				System.exit(0);
			}
		}
	}

}
